from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

class Base():
    def __init__(self ,driver):
        self.driver = driver
    # 打开指定网址
    def get_url(self, url):
        self.driver.get(url)
    # 等待元素出现
    def find_element(self , loc):
        WebDriverWait(self.driver,10,0.5).until(lambda driver:self.driver.find_element(*loc).is_displayed())
        return self.driver.find_element(*loc)
    # 获取元素文本值
    def get_text(self, loc):
        return self.find_element(loc).text
    # 点击元素
    def click(self, loc):
        self.find_element(loc).click()
    # 输入文本
    def send_keys(self, loc, text):
        self.find_element(loc).send_keys(text)
    # 获取页面标题
    def get_title(self):
        return self.driver.title
    # 回车
    def enter(self):
        ActionChains(self.driver).send_keys(Keys.ENTER).perform()
    # 滑动到底部
    def scroll(self):
        self.driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')
